package com.tool_stdy.thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * Created by yan_li on 2016/12/5.
 */
public class ThreadPool {

    public static void main(String[] args) throws InterruptedException {
        ExecutorService pool = Executors.newFixedThreadPool(3);
        int poolSize = ((ThreadPoolExecutor) pool).getPoolSize();
       // ((ThreadPoolExecutor)pool).allowCoreThreadTimeOut(true);
        System.out.println("poolSize:"+poolSize);//线程池内的大小数量
        final CountDownLatch latch1 = new CountDownLatch(1);
        for (int i = 0; i < 2; i++) {
            pool.execute(new Runnable() {
                @Override
                public void run() {
                    latch1.countDown();
                }
            });
        }
        latch1.await();

        int activeCount = ((ThreadPoolExecutor) pool).getActiveCount();
        long completedTaskCount = ((ThreadPoolExecutor) pool).getCompletedTaskCount();
        System.out.println(poolSize);
        System.out.println(activeCount);
        System.out.println(completedTaskCount);
        System.out.println( ((ThreadPoolExecutor)pool).allowsCoreThreadTimeOut());
        Thread.sleep(2000);
    }

}
